home *** CD-ROM | disk | FTP | other *** search
- program FontList;
-
- uses
- WObjects, WinTypes, WinProcs,Strings;
-
- {$I fontlist.inc}
- {$R fontlist.res}
-
- type
- PEnumer = ^TEnumer;
- TEnumer = record
- hGMem : THandle;
- nCount : Integer;
- end;
-
- PFont = ^TFont;
- TFont = record
- nFontType : Integer;
- lf : TLogFont;
- tm : TTextMetric;
- end;
-
-
- TFontApp = object ( TApplication )
- procedure InitMainWindow; virtual;
- end;
-
- PFontWindow = ^TFontWindow;
- TFontWindow = object ( TWindow )
- HaveInfo : Boolean;
- Enumer1,
- Enumer2 : TEnumer;
- EnumFacesProc : TFarProc;
- EnumFontsProc : TFarProc;
- cxChar,
- cyChar : Integer;
- nCurrent : Integer;
- CurrentDC : Word;
- constructor Init ( AParent: PWindowsObject; ATitle: PChar );
- destructor Done; virtual;
- procedure Paint ( PaintDC: HDC; var PaintInfo: TPaintStruct ); virtual;
- procedure Redraw;
- procedure SelectScreen( var Message: TMessage );
- virtual cm_First + cm_Screen;
- procedure SelectPrinter ( var Message: TMessage );
- virtual cm_First + cm_Printer;
- procedure WMDevModeChange ( var Message: TMessage );
- virtual wm_First + wm_DevModeChange;
- procedure WMFontChange( var Message: TMessage );
- virtual wm_First + wm_FontChange;
- procedure WMVScroll ( var Message: TMessage );
- virtual wm_First + wm_VScroll;
- end;
-
- var
- FontApp: TFontApp;
-
-
- function EnumAllFaces ( lf : PLogFont; tm : PTextMetric;
- FontType: Integer; Enumer : PEnumer ) : Integer; export;
- var
- lpFaces : Pointer;
- begin
- EnumAllFaces := 0;
- if GlobalReAlloc ( Enumer^.hGMem,
- LF_FACESIZE * ( 1 + Enumer^.nCount ),
- GMEM_MOVEABLE ) = 0 then
- Exit;
- lpFaces := GlobalLock ( Enumer^.hGMem );
- StrCopy ( PChar(LongInt(lpFaces)+ Enumer^.nCount * lf_FaceSize), lf^.lfFaceName );
- GlobalUnlock ( Enumer^.hGMem );
- Inc(Enumer^.nCount);
- EnumAllFaces := 1;
- end;
-
- function EnumAllFonts ( lf : PLogFont; tm : PTextMetric;
- nFontType: Integer; Enumer : PEnumer ) : Integer; export;
- var
- font : PFont;
- begin
- EnumAllFonts := 0;
- if GlobalReAlloc ( Enumer^.hGMem,
- sizeof ( TFont )* ( 1 + Enumer^.nCount ),
- gmem_MOVEABLE ) = 0 then
- Exit;
- font := PFont(GlobalLock ( Enumer^.hGMem ));
- font := PFont(Longint(font)+(Enumer^.nCount * sizeof ( TFont ) ) );
- font^.nFontType := nFontType;
- font^.lf := lf^;
- font^.tm := tm^;
- GlobalUnlock ( Enumer^.hGMem );
- Inc(Enumer^.nCount);
- EnumAllFonts:= 1;
- end;
-
- function StrTok ( Src : PChar; Sep: PChar ): PChar;
- const
- STSrc: PChar = NIL;
- var
- l : Integer;
- i : Integer;
- Temp : PChar;
- begin
- StrTok := NIL;
- if Src <> NIL then
- STSrc := Src;
- if STSrc = NIL then
- Exit;
-
- l := StrLen ( Sep );
- for i := 0 to l-1 do
- begin
- Temp := StrScan ( STSrc, Sep[i] );
- if Temp <> NIL then
- begin
- StrTok := STSrc;
- Temp^ := #0;
- STSrc := Temp + 1;
- Exit;
- end;
- end;
- StrTok := STSrc;
- STSrc := NIL;
- end;
-
-
- function GetPrinterIC : THandle;
- var
- szPrinter : array[0..64] of Char;
- szDevice, szDriver, szOutput : PChar;
- begin
- GetProfileString ( 'windows','device','', szPrinter, 64 );
- szDevice := StrTok ( szPrinter, ',' );
- szDriver := StrTok ( NIL, ',' );
- szOutput := StrTok ( NIL, ',' );
- if (szDevice <> NIL ) and
- (szDriver <> NIL ) and
- (szOutput <> NIL ) then
- GetPrinterIC := CreateIC ( szDriver, szDevice, szOutput, NIL )
- else
- GetPrinterIC := 0;
- end;
-
-
- procedure Display ( PaintDC: HDC; cx,cy : Integer; Font: PFont );
- type
- PCharArr = array[0..100] of PChar;
- PPCharArr = ^PCharArr;
- const
- F : TFont = ();
- First: Integer = 0;
- Last: Integer = 0;
- Default: Integer = 0;
- Break: Integer = 0;
-
- szYN : array[0..1] of PChar = ( 'No','Yes' );
- szCS : array[0..3] of PChar = ( 'ANSI','?????','Kanji','OEM' );
- szOP : array[0..3] of PChar = ( 'Default','String','Char','Stroke');
- szCP : array[0..3] of PChar = ( 'Default','Char','Stroke','?????' );
- szQU : array[0..3] of PChar = ( 'Draft','Default','Proof','?????' );
- szP1 : array[0..3] of PChar = ( 'Default','Fixed','Variable','?????' );
- szP2 : array[0..1] of PChar = ( 'Fixed','Variable' );
- szFA : array[0..7] of PChar = ( 'Don''t Care','Roman','Swiss','Modern',
- 'Script','Decorative','?????','?????' );
- szVR : array[0..1] of PChar = ( 'Stroke','Raster' );
- szGD : array[0..1] of PChar = ( 'GDI','Device');
-
- shorts: array[0..19] of record
- x : Integer;
- y : Integer;
- szFmt : PChar;
- PData : ^Integer;
- end =
- (
- ( x:1; y:1; szFmt:'LOGFONT'; PData:NIL ),
- ( x:1; y:2; szFmt:'-------'; PData:NIL ),
- ( x:1; y:3; szFmt:'Height: %10d'; PData:@f.lf.lfHeight),
- ( x:1; y:4; szFmt:'Width: %10d'; PData:@f.lf.lfWidth),
- ( x:1; y:5; szFmt:'Escapment %10d'; PData:@f.lf.lfEscapement),
- ( x:1; y:6; szFmt:'Orientation: %10d'; PData:@f.lf.lfOrientation),
- ( x:1; y:7; szFmt:'Weight: %10d'; PData:@f.lf.lfWeight),
- ( x:28; y:1; szFmt:'TEXTMETRIC'; pData:NIL),
- ( x:28; y:2; szFmt:'----------'; pData:NIL),
- ( x:28; y:3; szFmt:'Height: %5d'; PData:@f.tm.tmHeight),
- ( x:28; y:4; szFmt:'Ascent: %5d'; PData:@f.tm.tmAscent),
- ( x:28; y:5; szFmt:'Descent: %5d'; PData:@f.tm.tmDescent),
- ( x:28; y:6; szFmt:'Int. Leading: %5d'; PData:@f.tm.tmInternalLeading),
- ( x:28; y:7; szFmt:'Ext. Leading: %5d'; PData:@f.tm.tmExternalLeading),
- ( x:28; y:8; szFmt:'Ave. Width: %5d'; pData:@f.tm.tmAveCharWidth),
- ( x:28; y:9; szFmt:'Max. Width: %5d'; pData:@f.tm.tmMaxCharWidth),
- ( x:28; y:10; szFmt:'Weight: %5d'; pData:@f.tm.tmWeight),
- ( x:51; y:10; szFmt:'Overhang: %10d'; pData:@f.tm.tmOverhang),
- ( x:51; y:11; szFmt:'Digitized X: %10d'; pData:@f.tm.tmDigitizedAspectX ),
- ( x:51; y:12; szFmt:'Digitized Y; %10d'; pData:@f.tm.tmDigitizedAspectY));
-
- bytes : array[0..3] of record
- x,y: Integer; szFmt: PChar; pData: ^Byte;
- end =
- ( ( x:51; y:3; szFmt:'FirstChar: %10d'; pData:@First),
- ( x:51; y:4; szFmt:'Last Char: %10d'; pData:@Last),
- ( x:51; y:5; szFmt:'Default Char: %10d'; pData:@Default),
- ( x:51; y:6; szFmt:'Break Char: %10d'; pData:@Break) );
-
- strs : array[0..16] of record
- x,y: Integer; szFmt: PChar; pData:^Byte; szArray:PPCharArr;
- sAnd: Integer; sShift: Integer;
- end =
- ( ( x:1; y:8; szFmt:'Italic: %10s';pData:@f.lf.lfItalic; szArray:@szYn; sAnd:1; sShift:0),
- ( x:1; y:9; szFmt:'Underline: %10s';pData:@f.lf.lfUnderline; szArray:@szYN; sAnd:1; sShift:0),
- ( x:1; y:10; szFmt:'Strike-Out %10s';pData:@f.lf.lfStrikeOut; szArray:@szYN; sAnd:1; sShift:0),
- ( x:1; y:11; szFmt:'Char Set: %10s';pData:@f.lf.lfCharSet; szArray:@szCS; sAnd:$C0; sShift:6),
- ( x:1; y:12; szFmt:'Out Prec: %10s';pData:@f.lf.lfOutPrecision; szArray:@szOP; sAnd:3; sShift:0),
- ( x:1; y:13; szFmt:'Clip Prec: %10s';pData:@f.lf.lfClipPrecision; szArray:@szCP; sAnd:3; sShift:0),
- ( x:1; y:14; szFmt:'Quality: %10s';pData:@f.lf.lfQuality; szArray:@szQU; sAnd:3; sShift:0),
- ( x:1; y:15; szFmt:'Pitch: %10s';pData:@f.lf.lfPitchAndFamily; szArray:@szP1; sAnd:3; sShift:0),
- ( x:1; y:16; szFmt:'Family: %10s';pData:@f.lf.lfPitchAndFamily; szArray:@szFA; sAnd:$70; sShift:4),
- ( x:28; y:11; szFmt:'Italic: %5s';pData:@f.tm.tmItalic; szArray:@szYN; sAnd:1; sShift:0),
- ( x:28; y:12; szFmt:'Underline: %5s';pData:@f.tm.tmUnderlined; szArray:@szYN; sAnd:1; sShift:0),
- ( x:28; y:13; szFmt:'Strike-Out: %5s';pData:@f.tm.tmStruckOut; szArray:@szYN; sAnd:1; sShift:0),
- ( x:51; y:7; szFmt:'Pitch: %10s';pData:@f.tm.tmPitchAndFamily; szArray:@szP2; sAnd:1; sShift:0),
- ( x:51; y:8; szFmt:'Family: %10s';pData:@f.tm.tmPitchAndFamily; szArray:@szFA; sAnd:$70; sShift:4),
- ( x:51; y:9; szFmt: 'Char Set: %10s';pData:@f.tm.tmCharSet; szArray:@szCS; sAnd:$C0; sShift:6),
- ( x:36; y:15; szFmt:'Font Type: %6s';pData:@f.nFontType; szArray:@szVR; sAnd:1; sShift:0),
- ( x:55; y:15; szFmt:'%s'; pData:@f.nFontType; szArray:@szGD; sAnd:2; sShift:1 ));
-
-
- var
- szBuffer : array[0..80] of Char;
- i: Integer;
- szParms : array[0..0] of Pointer;
- begin
- f := Font^;
- First := f.tm.tmFirstChar;
- Last := f.tm.tmLastChar;
- Default := f.tm.tmDefaultChar;
- Break := f.tm.tmBreakChar;
- for i := 0 to 19 do
- TextOut ( PaintDC, cx * shorts[i].x, cy * shorts[i].y, szBuffer,
- wvsprintf ( szBuffer, shorts[i].szFmt, shorts[i].pData^) );
- for i := 0 to 3 do
- TextOut ( PaintDC, cx * bytes[i].x, cy * bytes[i].y, szBuffer,
- wvsprintf ( szBuffer, bytes[i].szFmt, bytes[i].pData^) );
- for i := 0 to 16 do
- TextOut ( PaintDC, cx * strs[i].x, cy * strs[i].y, szBuffer,
- wvsprintf ( szBuffer, strs[i].szFmt,
- strs[i].szArray^[(strs[i].pData^ and strs[i].sAnd) shr strs[i].sShift]) );
- StrCopy(szBuffer ,'Face Name: ');
- StrCat( szBuffer, f.lf.lfFaceName );
- TextOut( PaintDC, cx * 36, cy * 16, szBuffer, StrLen ( szBuffer ) );
- end;
-
-
-
- procedure TFontApp.InitMainWindow;
- begin
- MainWindow := New ( PFontWindow, Init( NIL, 'Font Enumeration' ) );
- end;
-
- constructor TFontWindow.Init ( AParent: PWindowsObject; ATitle: PChar );
- var
- DC: HDC;
- tm: TTextMetric;
- begin
- TWindow.Init ( AParent, ATitle );
- Attr.Style := Attr.Style or ws_VScroll or ws_HScroll;
- Attr.Menu := LoadMenu ( HInstance, 'MAINMENU');
-
- HaveInfo := FALSE;
- FillChar ( Enumer1, sizeof ( Enumer1 ), 0 );
- FillChar ( Enumer2, sizeof ( Enumer2 ), 0 );
- EnumFontsProc := MakeProcInstance( @EnumAllFonts, hInstance );
- EnumFacesProc := MakeProcInstance( @EnumAllFaces, hInstance );
- CurrentDC := cm_Screen;
- CheckMenuItem ( Attr.Menu, CurrentDC, mf_Checked );
- DC := GetDC ( hWindow );
- SelectObject ( DC, GetStockObject ( System_Fixed_Font ) );
- GetTextMetrics ( DC, tm );
- cxChar := tm.tmAveCharWidth;
- cyChar := tm.tmHeight + tm.tmExternalLeading;
- ReleaseDC ( hWindow, DC );
- end;
-
- destructor TFontWindow.Done;
- begin
- if Enumer2.hGMem <> 0 then
- GlobalFree ( Enumer2.hGMem );
- TWindow.Done;
- end;
-
- procedure TFontWindow.Paint( PaintDC: HDC; var PaintInfo: TPaintStruct );
- var
- DC: HDC;
- Faces: Pointer;
- Font: PFont;
- OldFont : HFONT;
- i: Integer;
- begin
- TWindow.Paint ( PaintDC, PaintInfo );
- if not HaveInfo then
- begin
- if Enumer2.hGMem <> 0 then
- GlobalFree ( Enumer2.hGMem );
- Enumer1.hGMem := GlobalAlloc ( gmem_Fixed, 1 );
- Enumer1.nCount := 0;
-
- Enumer2.hGMem := GlobalAlloc ( gmem_Fixed, 1 );
- Enumer2.nCount := 0;
-
- if ( Enumer1.hGMem = 0 ) or ( Enumer2.hGMem = 0 ) then
- begin
- FontApp.Error( em_OutOfMemory );
- Exit;
- end;
-
- if ( CurrentDC = cm_Screen ) then
- DC := CreateIC ( 'DISPLAY', NIL, NIL, NIL )
- else
- DC := GetPrinterIC;
-
- if DC <> 0 then
- begin
- if EnumFonts ( DC, NIL, EnumFacesProc, @Enumer1 ) = 0 then
- begin
- FontApp.Error ( em_OutOfMemory );
- Exit;
- end;
- Faces := GlobalLock ( Enumer1.hGMem );
- for i := 0 to ENumer1.NCount - 1 do
- begin
- if EnumFonts ( DC, Pointer(Longint(Faces)+ (i * lf_FaceSize) ),
- EnumFontsProc, @Enumer2 ) = 0 then
- begin
- FontApp.Error ( em_OutOfMemory );
- Exit;
- end;
- end;
-
- GlobalUnlock ( Enumer1.hGMem );
- Dec ( Enumer2.nCount );
- DeleteDC ( DC );
- HaveInfo := True;
- end;
- GlobalFree ( Enumer1.hGMem );
- SetScrollRange ( HWindow, sb_Vert, 0, Enumer2.nCount, FALSE );
- SetScrollPos ( HWindow, sb_Vert, 0, TRUE );
- nCurrent := 0;
- end;
-
- if HaveInfo then
- begin
- SelectObject ( PaintDC, GetStockObject ( System_Fixed_Font ) );
- Font := PFont ( GlobalLock ( Enumer2.hGMem ) );
- Font := PFont(Longint(Font)+ (nCurrent * sizeof ( TFont ) ));
- Display ( PaintDC, cxChar, cyChar, Font );
- OldFont := SelectObject ( PaintDC, CreateFontIndirect ( Font^.lf ) );
- TextOut ( PaintDC, 1 * cxChar, 19 * cyChar,
- 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz', 52 );
- GlobalUnlock ( Enumer2.hGMem );
- DeleteObject ( SelectObject( PaintDC, OldFont ) );
- end;
- end;
-
- procedure TFontWindow.Redraw;
- begin
- HaveInfo := FALSE;
- InvalidateRect ( HWindow, NIL, TRUE );
- end;
-
-
- procedure TFontWindow.SelectScreen( var Message: TMessage );
- var
- Menu: HMenu;
- begin
- Menu := GetMenu ( HWindow );
- CheckMenuItem ( Menu, CurrentDC, mf_Unchecked );
- CheckMenuItem ( Menu, cm_Screen, mf_Checked );
- CurrentDC := cm_Screen;
- Redraw;
- end;
-
-
- procedure TFontWindow.SelectPrinter ( var Message: TMessage );
- var
- Menu: HMenu;
- begin
- Menu := GetMenu ( HWindow );
- CheckMenuItem ( Menu, CurrentDC, mf_Unchecked );
- CheckMenuItem ( Menu, cm_Printer, mf_Checked );
- CurrentDC := cm_Printer;
- Redraw;
- end;
-
-
- procedure TFontWindow.WMDevModeChange ( var Message: TMessage );
- begin
- Redraw;
- end;
-
- procedure TFontWIndow.WMFontChange( var Message: TMessage );
- begin
- Redraw;
- end;
-
-
- procedure TFontWindow.WMVScroll ( var Message: TMessage );
- begin
- case Message.wParam of
- sb_Top: nCurrent := 0;
- sb_Bottom: nCurrent := Enumer2.nCount;
- sb_LineUp,
- sb_PageUp: Dec(nCurrent);
- sb_LineDown,
- sb_PageDown: Inc ( nCurrent );
- sb_ThumbPosition: nCurrent := Message.lParamLo;
- else
- Exit;
- end;
- if nCurrent < 0 then
- nCurrent := 0
- else
- if nCurrent > Enumer2.nCount then
- nCurrent := Enumer2.nCount;
- SetScrollPos ( HWindow, sb_Vert, nCurrent, TRUE );
- InvalidateRect ( HWindow, NIL, TRUE );
- end;
-
-
-
-
- begin
- FontApp.Init ( 'FontList' );
- FontApp.Run;
- FontApp.Done;
- end.